package cn.operation.api.rest;


import cn.operation.backend.query.BaseLnLineQueryConditions;
import cn.operation.backend.service.baseArea.BaseAreaService;
import cn.operation.backend.util.BusinessException;
import cn.operation.backend.util.ResultDTOWithPagination;
import cn.operation.base.model.ScBaseArea;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping(value = "/api/line", produces = MediaType.APPLICATION_JSON_VALUE)
@Api(value = "/api/line", description = "线路API")
public class ScBaseLnLineRest {

	private static final Logger LOGGER = LoggerFactory.getLogger(ScBaseLnLineRest.class);

	@Autowired
	private BaseAreaService baseAreaService;

	@ResponseBody
	@RequestMapping(value = "/queryStartArea/{areaKeyword}", method = RequestMethod.GET)
	@ApiOperation(value = "查询渠道线路起点区域", notes = "查询渠道线路起点区域", produces = MediaType.APPLICATION_JSON_VALUE)
	@ApiResponses(value = {@ApiResponse(code = 400, message = "Invalid Code supplied"),
			@ApiResponse(code = 404, message = "data not found")})
	public ResultDTOWithPagination<Object> queryStartArea(
			@ApiParam(value = "区域关键字") @PathVariable("areaKeyword") String areaKeyword) throws Exception {
		LOGGER.info("LnLineRest.queryStartArea param: {}", areaKeyword);
		ResultDTOWithPagination<Object> result = new ResultDTOWithPagination<>(true, null, "查询成功！");
		try {
			BaseLnLineQueryConditions conditions = new BaseLnLineQueryConditions();
			if ("undefined".equals(areaKeyword) || "null".equals(areaKeyword))
				areaKeyword = null;
			if (areaKeyword != null)
				conditions.setAreaKeyword(areaKeyword);
			List<ScBaseArea> list = baseAreaService.queryStartArea(null, conditions);

			result.setData(list);

		} catch (Exception e) {
			LOGGER.error("LnLineRest.queryStartArea error: {}", e);
			throw new BusinessException(e.getMessage());
		}
		return result;
	}



}
